<?php

/**
 * 货代公司 
 */
class Application_Model_AgentCompany extends Application_Model_DomainObject{
    
    protected $_id;
    
    protected $_name;
    
    protected $_linkman;//联系人姓名
    
    protected $_tel;//联系电话
    
    protected $_address;//联系QQ
    
    protected $_url;//描术
    
    protected $_host;
   
    protected $_username;
    
    protected $_password;
    
    protected $_isDisable;
    /**
     * 定义递四方的Id
     */
    const Agent_4px = 1;
     /**
     * 定义互联易的Id
     */
    const Agent_hlt = 3;
    /**
     * 定义商易的Id
     */
    const Agent_SY = 8;

    /**
     * 获取全部的发货渠道
     * @return type
     */
    public static function getAgentAll()
    {
        return self::getDao()->queryAll(array("isDisable = " => 0));
    }
    public static function getAgentOne($id)
    {
        $where[' id = '] = $id;
        $db = new Application_Model_DbTable_AgentCompany();
        $result = $db->queryOne($where);
        return $result;
    } 

    public static function getEffectivelyAgent() {
        $db = new Application_Model_DbTable_agentcompany();
        return $db->getEffectivelyAgent();
    }

    public function getBillAll()
    {
        $editAgentItem = Application_Model_WayLog::getTypeByWayBill(Application_Model_WayLog::Type_BillAffirmAgent); 
        $billId = "(";
        if($editAgentItem){
            foreach ($editAgentItem as $agentVal) {
                $billId .= $agentVal->wayId.",";
            }
        }
        $billId .= "0)";
        $where[" id not in "] = $billId;
        $where[" and agentId = "] = $this->_id;
        $where[" and interior = "] = Application_Model_wayBillItem::Interior_AffirmChannel;
        $where[" and ( problem = 0 or problem is null or problem = 2) and "] = 1;
        return Application_Model_wayBillItem::getDao()->queryAll($where," expressId desc ");
    }

    public function getEditBillAll()
    {
        $editAgentItem = Application_Model_WayLog::getAgentIdTypeByWayBill($this->_id,Application_Model_WayLog::Type_BillAffirmAgent);
        $billId = "(";
        if($editAgentItem){
            foreach ($editAgentItem as $agentVal) {
                $billId .= $agentVal->wayId.",";
            }
        }
        $billId .= "0)";
        $where[" id in "] = $billId;
        $where[" and interior = "] = Application_Model_wayBillItem::Interior_AffirmChannel;
        $where[" and ( problem = 0 or problem is null or problem = 2) and "] = 1;
        return Application_Model_wayBillItem::getDao()->queryAll($where," expressId desc ");
    }

    public function getDisableName()
    {
        if($this->_isDisable == 1){
            return "禁用";
        } else {
            return "启用";
        }
    }
    
    public static function getPriceFilteds($quick,$isDisable,$pagesize,$pageindex)
    {
        $where = array();
        $and = "";
        if($quick != "")
        {
            $where[$and." ( name like "] = "%".$quick."%";
            $and = " or ";
            $where[$and." linkman like "] = "%".$quick."%";
            $where[$and." username like "] = "%".$quick."%";
            $where[" ) and 1 = "] = 1;
            $and = " and ";
        }
        if($isDisable !== "")
        {
            $where[$and." isDisable = "] = $isDisable;
            $and = " and ";
        }
        return self::getDao()->queryPage($where, " id asc ", $pagesize, $pageindex);
    }
    
}

